import Mock from 'mockjs'


// {
//     id: 1,
//     code: 1000002,
//     name: "头孢颗粒",
//     standards: "药品规格",
//     count: 1,
//     type: "盒",
//     price: 100,
//     total: 200,
//   },

var DrugList = [];
for(var i = 0;i<10;i++){
    DrugList.push({
        id:i+1,
        code:100000+i+1,
        name:Mock.mock('@ctitle()'),
        standards:'药品规格',
        count:1,
        type: Mock.mock({
            "array|1": [
                "盒",
                "瓶",
                "粒",
            ]
        }).array,
        price:Mock.mock('@natural(0, 100)'),
    })
}
var  ListData = JSON.parse(JSON.stringify(DrugList))

export default{
    DrugData:config=>{
        return{
            code:200,
            mesg:'初始化成功',
            data:DrugList,
        }
    },
    deleteDrug:config=>{
        var id= JSON.parse(config.body);
        console.log(config.body)
        console.log("is",id)
        var res = DrugList.filter(item => item.id!=id);
        DrugList = res;

        return{
            code:200,
            mesg:'删除成功',
            data:null
        }
    },
    addDrug:config=>{
        var obj =  JSON.parse(config.body);
        console.log(obj)
        obj.id = DrugList.length+1;
        obj.standards="药品规格";
        console.log(obj)
        DrugList.push(obj)
        return{
            code:200,
            mesg:'添加成功',
            data:DrugList,
        }
    },
    ListDrug:config=>{
        return{
            code:200,
            mesg:'榜单渲染成功',
            data:ListData,
        }
    }
}